package com.linden.std.controller.admin;

import com.linden.std.annotation.RequiresPermissions;
import com.linden.std.domain.vo.UserVO;
import com.linden.std.result.Result;
import com.linden.std.service.ISysUserService;
import com.linden.std.Utils.UserContextUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 用户管理控制器
 */
@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private ISysUserService userService;

    @GetMapping("/profile")
    @ApiOperation("获取个人信息")
    public Result<UserVO> getProfile() {
        UserVO userVO = UserContextUtil.getUser();
        return Result.success(userVO);
    }

    @GetMapping("/list")
    @ApiOperation("获取用户列表")
    @PreAuthorize("hasAuthority('system:user:list')")
    @RequiresPermissions("system:user:list")
    public Result<String> getUserList() {
        // 演示权限控制
        return Result.success("用户列表数据");
    }

    @PostMapping("/add")
    @ApiOperation("添加用户")
    @PreAuthorize("hasAuthority('system:user:add')")
    @RequiresPermissions("system:user:add")
    public Result<String> addUser() {
        // 演示权限控制
        return Result.success("添加用户成功");
    }

    @PutMapping("/edit")
    @ApiOperation("编辑用户")
    @PreAuthorize("hasAuthority('system:user:edit')")
    @RequiresPermissions("system:user:edit")
    public Result<String> editUser() {
        // 演示权限控制
        return Result.success("编辑用户成功");
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除用户")
    @PreAuthorize("hasAuthority('system:user:delete')")
    @RequiresPermissions("system:user:delete")
    public Result<String> deleteUser() {
        // 演示权限控制
        return Result.success("删除用户成功");
    }
}